﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using nr.GLV.Windows.Controls;

namespace nr.GLV.Windows
{
    public partial class CitiesDatagrid : ArchiveUserControl
    {
        public CitiesDatagrid()
        {
            InitializeComponent();
            FilterFields.Clear();

            FilterFields.AddRange(
                new FilterField[]{
                    new FilterField("Denominazione","Name"),
                    new FilterField("Provincia", "District"),
                    new FilterField("Regione","Region"),
                    new FilterField("C.A.P.", "ZIP")
                });
        }

        protected override void OnDataChanged(EventArgs e)
        {
            base.OnDataChanged(e);

            statesBindingSource.DataSource = Data;
            citiesBindingSource.DataSource = Data;
        }

        private void dgCities_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
        {
            OnRecordCountChanged(new RecordCountChangedEventArgs(Title, dgCities.Rows.Count));
        }

        private void dgCities_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
        {
            OnRecordCountChanged(new RecordCountChangedEventArgs(Title, dgCities.Rows.Count));
        }

        private void dgCities_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            OnRecordCountChanged(new RecordCountChangedEventArgs(Title, dgCities.Rows.Count));
        }

        protected override void OnFilterReset(EventArgs e)
        {
            base.OnFilterReset(e);
            citiesBindingSource.RemoveFilter();
        }

        protected override void OnFilterApply(EventArgs e)
        {
            base.OnFilterApply(e);
            citiesBindingSource.Filter = GetFilters();
        }
    }
}
